Skip to contents

Map - County polygons / boundaries - Create leaflet or static map of results of analysis

Usage

mapfastej_counties(
  mydf,
  colorvarname = "pctile.Demog.Index.Supp",
  colorfills = c("darkgray", "yellow", "orange", "darkred"),
  colorlabels = c("<80", "80-89", "90-94", "95+"),
  colorbins = c(0, 80, 90, 95, 100),
  colorpalette = c("gray", "yellow", "orange", "red"),
  static_not_leaflet = FALSE,
  main = "Selected Counties",
  fillOpacity = 0.5,
  ...
)

Arguments

mydf

something like ejamit(fips = fips_counties_from_statename("Kentucky"), radius = 0)$results_bysite

colorvarname

colname of indicator in mydf that drives color-coding (or alternatively, colorvarname = "green" means a single specific color for all, like "green")

colorfills

vector of colors shown in legend

colorlabels

vector of cutoffs shown in legend

colorbins

vector of cutoffs for which values of colorvarname indicator get assigned which colors from colorpalette

colorpalette

vector of colors available for filling polygons

static_not_leaflet

set TRUE to use map_shapes_plot() instead of map_shapes_leaflet()

main

title for map

fillOpacity

passed to map_shapes_leaflet() which passes it to leaflet::addPolygons()

...

depending on value of static_not_leaflet T/F, passed to map_shapes_plot() or to map_shapes_leaflet() which passes it to leaflet::addPolygons(), such as opacity=1

Value

leaflet html widget (but if static_not_leaflet=T, returns just shapes_counties_from_countyfips(mydf$ejam_uniq_id))

Details

THIS ASSUMES THAT mydf$ejam_unique_id is the county FIPS codes.

IMPORTANT: The percentiles shown are percentiles among blockgroups, not counties. A county here shown as being at 90th percentile actually is one where the average resident in the county is in a blockgroup that is at the 90th percentile of blockgroups in the US (or the State, depending on colorvarname).

Examples

# \donttest{
myfips = fips_counties_from_state_abbrev(c("AL", "GA", "MS"))
mydf = ejamit(fips = myfips )$results_bysite
#> Finding blocks in each FIPS Census unit.
#> Aggregating at each FIPS Census unit and overall.
mapfastej_counties(mydf, colorvarname = "pctile.pctnhba" )
#> Warning: need tidycensus package and census API key to use myservice = 'cartographic', so using default service instead
#> Reading layer `OGRGeoJSON' from data source 
#>   `https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Boundaries_2022/FeatureServer/2/query?where=FIPS%3D%2701001%27%20OR%20FIPS%3D%2701003%27%20OR%20FIPS%3D%2701005%27%20OR%20FIPS%3D%2701007%27%20OR%20FIPS%3D%2701009%27%20OR%20FIPS%3D%2701011%27%20OR%20FIPS%3D%2701013%27%20OR%20FIPS%3D%2701015%27%20OR%20FIPS%3D%2701017%27%20OR%20FIPS%3D%2701019%27%20OR%20FIPS%3D%2701021%27%20OR%20FIPS%3D%2701023%27%20OR%20FIPS%3D%2701025%27%20OR%20FIPS%3D%2701027%27%20OR%20FIPS%3D%2701029%27%20OR%20FIPS%3D%2701031%27%20OR%20FIPS%3D%2701033%27%20OR%20FIPS%3D%2701035%27%20OR%20FIPS%3D%2701037%27%20OR%20FIPS%3D%2701039%27%20OR%20FIPS%3D%2701041%27%20OR%20FIPS%3D%2701043%27%20OR%20FIPS%3D%2701045%27%20OR%20FIPS%3D%2701047%27%20OR%20FIPS%3D%2701049%27%20OR%20FIPS%3D%2701051%27%20OR%20FIPS%3D%2701053%27%20OR%20FIPS%3D%2701055%27%20OR%20FIPS%3D%2701057%27%20OR%20FIPS%3D%2701059%27%20OR%20FIPS%3D%2701061%27%20OR%20FIPS%3D%2701063%27%20OR%20FIPS%3D%2701065%27%20OR%20FIPS%3D%2701067%27%20OR%20FIPS%3D%2701069%27%20OR%20FIPS%3D%2701071%27%20OR%20FIPS%3D%2701073%27%20OR%20FIPS%3D%2701075%27%20OR%20FIPS%3D%2701077%27%20OR%20FIPS%3D%2701079%27%20OR%20FIPS%3D%2701081%27%20OR%20FIPS%3D%2701083%27%20OR%20FIPS%3D%2701085%27%20OR%20FIPS%3D%2701087%27%20OR%20FIPS%3D%2701089%27%20OR%20FIPS%3D%2701091%27%20OR%20FIPS%3D%2701093%27%20OR%20FIPS%3D%2701095%27%20OR%20FIPS%3D%2701097%27%20OR%20FIPS%3D%2701099%27&outFields=NAME%2CFIPS%2CSTATE_ABBR%2CSTATE_NAME&returnGeometry=true&f=geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 50 features and 4 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -88.47323 ymin: 30.22093 xmax: -84.99943 ymax: 35.00803
#> Geodetic CRS:  WGS 84
#> Reading layer `OGRGeoJSON' from data source 
#>   `https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Boundaries_2022/FeatureServer/2/query?where=FIPS%3D%2701101%27%20OR%20FIPS%3D%2701103%27%20OR%20FIPS%3D%2701105%27%20OR%20FIPS%3D%2701107%27%20OR%20FIPS%3D%2701109%27%20OR%20FIPS%3D%2701111%27%20OR%20FIPS%3D%2701113%27%20OR%20FIPS%3D%2701115%27%20OR%20FIPS%3D%2701117%27%20OR%20FIPS%3D%2701119%27%20OR%20FIPS%3D%2701121%27%20OR%20FIPS%3D%2701123%27%20OR%20FIPS%3D%2701125%27%20OR%20FIPS%3D%2701127%27%20OR%20FIPS%3D%2701129%27%20OR%20FIPS%3D%2701131%27%20OR%20FIPS%3D%2701133%27%20OR%20FIPS%3D%2713001%27%20OR%20FIPS%3D%2713003%27%20OR%20FIPS%3D%2713005%27%20OR%20FIPS%3D%2713007%27%20OR%20FIPS%3D%2713009%27%20OR%20FIPS%3D%2713011%27%20OR%20FIPS%3D%2713013%27%20OR%20FIPS%3D%2713015%27%20OR%20FIPS%3D%2713017%27%20OR%20FIPS%3D%2713019%27%20OR%20FIPS%3D%2713021%27%20OR%20FIPS%3D%2713023%27%20OR%20FIPS%3D%2713025%27%20OR%20FIPS%3D%2713027%27%20OR%20FIPS%3D%2713029%27%20OR%20FIPS%3D%2713031%27%20OR%20FIPS%3D%2713033%27%20OR%20FIPS%3D%2713035%27%20OR%20FIPS%3D%2713037%27%20OR%20FIPS%3D%2713039%27%20OR%20FIPS%3D%2713043%27%20OR%20FIPS%3D%2713045%27%20OR%20FIPS%3D%2713047%27%20OR%20FIPS%3D%2713049%27%20OR%20FIPS%3D%2713051%27%20OR%20FIPS%3D%2713053%27%20OR%20FIPS%3D%2713055%27%20OR%20FIPS%3D%2713057%27%20OR%20FIPS%3D%2713059%27%20OR%20FIPS%3D%2713061%27%20OR%20FIPS%3D%2713063%27%20OR%20FIPS%3D%2713065%27%20OR%20FIPS%3D%2713067%27&outFields=NAME%2CFIPS%2CSTATE_ABBR%2CSTATE_NAME&returnGeometry=true&f=geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 50 features and 4 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -88.46444 ymin: 30.35576 xmax: -80.83984 ymax: 34.98765
#> Geodetic CRS:  WGS 84
#> Reading layer `OGRGeoJSON' from data source 
#>   `https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Boundaries_2022/FeatureServer/2/query?where=FIPS%3D%2713069%27%20OR%20FIPS%3D%2713071%27%20OR%20FIPS%3D%2713073%27%20OR%20FIPS%3D%2713075%27%20OR%20FIPS%3D%2713077%27%20OR%20FIPS%3D%2713079%27%20OR%20FIPS%3D%2713081%27%20OR%20FIPS%3D%2713083%27%20OR%20FIPS%3D%2713085%27%20OR%20FIPS%3D%2713087%27%20OR%20FIPS%3D%2713089%27%20OR%20FIPS%3D%2713091%27%20OR%20FIPS%3D%2713093%27%20OR%20FIPS%3D%2713095%27%20OR%20FIPS%3D%2713097%27%20OR%20FIPS%3D%2713099%27%20OR%20FIPS%3D%2713101%27%20OR%20FIPS%3D%2713103%27%20OR%20FIPS%3D%2713105%27%20OR%20FIPS%3D%2713107%27%20OR%20FIPS%3D%2713109%27%20OR%20FIPS%3D%2713111%27%20OR%20FIPS%3D%2713113%27%20OR%20FIPS%3D%2713115%27%20OR%20FIPS%3D%2713117%27%20OR%20FIPS%3D%2713119%27%20OR%20FIPS%3D%2713121%27%20OR%20FIPS%3D%2713123%27%20OR%20FIPS%3D%2713125%27%20OR%20FIPS%3D%2713127%27%20OR%20FIPS%3D%2713129%27%20OR%20FIPS%3D%2713131%27%20OR%20FIPS%3D%2713133%27%20OR%20FIPS%3D%2713135%27%20OR%20FIPS%3D%2713137%27%20OR%20FIPS%3D%2713139%27%20OR%20FIPS%3D%2713141%27%20OR%20FIPS%3D%2713143%27%20OR%20FIPS%3D%2713145%27%20OR%20FIPS%3D%2713147%27%20OR%20FIPS%3D%2713149%27%20OR%20FIPS%3D%2713151%27%20OR%20FIPS%3D%2713153%27%20OR%20FIPS%3D%2713155%27%20OR%20FIPS%3D%2713157%27%20OR%20FIPS%3D%2713159%27%20OR%20FIPS%3D%2713161%27%20OR%20FIPS%3D%2713163%27%20OR%20FIPS%3D%2713165%27%20OR%20FIPS%3D%2713167%27&outFields=NAME%2CFIPS%2CSTATE_ABBR%2CSTATE_NAME&returnGeometry=true&f=geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 50 features and 4 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -85.60517 ymin: 30.59155 xmax: -81.1195 ymax: 34.98846
#> Geodetic CRS:  WGS 84
#> Reading layer `OGRGeoJSON' from data source 
#>   `https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Boundaries_2022/FeatureServer/2/query?where=FIPS%3D%2713169%27%20OR%20FIPS%3D%2713171%27%20OR%20FIPS%3D%2713173%27%20OR%20FIPS%3D%2713175%27%20OR%20FIPS%3D%2713177%27%20OR%20FIPS%3D%2713179%27%20OR%20FIPS%3D%2713181%27%20OR%20FIPS%3D%2713183%27%20OR%20FIPS%3D%2713185%27%20OR%20FIPS%3D%2713187%27%20OR%20FIPS%3D%2713189%27%20OR%20FIPS%3D%2713191%27%20OR%20FIPS%3D%2713193%27%20OR%20FIPS%3D%2713195%27%20OR%20FIPS%3D%2713197%27%20OR%20FIPS%3D%2713199%27%20OR%20FIPS%3D%2713201%27%20OR%20FIPS%3D%2713205%27%20OR%20FIPS%3D%2713207%27%20OR%20FIPS%3D%2713209%27%20OR%20FIPS%3D%2713211%27%20OR%20FIPS%3D%2713213%27%20OR%20FIPS%3D%2713215%27%20OR%20FIPS%3D%2713217%27%20OR%20FIPS%3D%2713219%27%20OR%20FIPS%3D%2713221%27%20OR%20FIPS%3D%2713223%27%20OR%20FIPS%3D%2713225%27%20OR%20FIPS%3D%2713227%27%20OR%20FIPS%3D%2713229%27%20OR%20FIPS%3D%2713231%27%20OR%20FIPS%3D%2713233%27%20OR%20FIPS%3D%2713235%27%20OR%20FIPS%3D%2713237%27%20OR%20FIPS%3D%2713239%27%20OR%20FIPS%3D%2713241%27%20OR%20FIPS%3D%2713243%27%20OR%20FIPS%3D%2713245%27%20OR%20FIPS%3D%2713247%27%20OR%20FIPS%3D%2713249%27%20OR%20FIPS%3D%2713251%27%20OR%20FIPS%3D%2713253%27%20OR%20FIPS%3D%2713255%27%20OR%20FIPS%3D%2713257%27%20OR%20FIPS%3D%2713259%27%20OR%20FIPS%3D%2713261%27%20OR%20FIPS%3D%2713263%27%20OR%20FIPS%3D%2713265%27%20OR%20FIPS%3D%2713267%27%20OR%20FIPS%3D%2713269%27&outFields=NAME%2CFIPS%2CSTATE_ABBR%2CSTATE_NAME&returnGeometry=true&f=geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 50 features and 4 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -85.42186 ymin: 30.62397 xmax: -81.13042 ymax: 35.00131
#> Geodetic CRS:  WGS 84
#> Reading layer `OGRGeoJSON' from data source 
#>   `https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Boundaries_2022/FeatureServer/2/query?where=FIPS%3D%2713271%27%20OR%20FIPS%3D%2713273%27%20OR%20FIPS%3D%2713275%27%20OR%20FIPS%3D%2713277%27%20OR%20FIPS%3D%2713279%27%20OR%20FIPS%3D%2713281%27%20OR%20FIPS%3D%2713283%27%20OR%20FIPS%3D%2713285%27%20OR%20FIPS%3D%2713287%27%20OR%20FIPS%3D%2713289%27%20OR%20FIPS%3D%2713291%27%20OR%20FIPS%3D%2713293%27%20OR%20FIPS%3D%2713295%27%20OR%20FIPS%3D%2713297%27%20OR%20FIPS%3D%2713299%27%20OR%20FIPS%3D%2713301%27%20OR%20FIPS%3D%2713303%27%20OR%20FIPS%3D%2713305%27%20OR%20FIPS%3D%2713307%27%20OR%20FIPS%3D%2713309%27%20OR%20FIPS%3D%2713311%27%20OR%20FIPS%3D%2713313%27%20OR%20FIPS%3D%2713315%27%20OR%20FIPS%3D%2713317%27%20OR%20FIPS%3D%2713319%27%20OR%20FIPS%3D%2713321%27%20OR%20FIPS%3D%2728001%27%20OR%20FIPS%3D%2728003%27%20OR%20FIPS%3D%2728005%27%20OR%20FIPS%3D%2728007%27%20OR%20FIPS%3D%2728009%27%20OR%20FIPS%3D%2728011%27%20OR%20FIPS%3D%2728013%27%20OR%20FIPS%3D%2728015%27%20OR%20FIPS%3D%2728017%27%20OR%20FIPS%3D%2728019%27%20OR%20FIPS%3D%2728021%27%20OR%20FIPS%3D%2728023%27%20OR%20FIPS%3D%2728025%27%20OR%20FIPS%3D%2728027%27%20OR%20FIPS%3D%2728029%27%20OR%20FIPS%3D%2728031%27%20OR%20FIPS%3D%2728033%27%20OR%20FIPS%3D%2728035%27%20OR%20FIPS%3D%2728037%27%20OR%20FIPS%3D%2728039%27%20OR%20FIPS%3D%2728041%27%20OR%20FIPS%3D%2728043%27%20OR%20FIPS%3D%2728045%27%20OR%20FIPS%3D%2728047%27&outFields=NAME%2CFIPS%2CSTATE_ABBR%2CSTATE_NAME&returnGeometry=true&f=geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 50 features and 4 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -91.65502 ymin: 30.17411 xmax: -81.61201 ymax: 34.99611
#> Geodetic CRS:  WGS 84
#> Reading layer `OGRGeoJSON' from data source 
#>   `https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Boundaries_2022/FeatureServer/2/query?where=FIPS%3D%2728049%27%20OR%20FIPS%3D%2728051%27%20OR%20FIPS%3D%2728053%27%20OR%20FIPS%3D%2728055%27%20OR%20FIPS%3D%2728057%27%20OR%20FIPS%3D%2728059%27%20OR%20FIPS%3D%2728061%27%20OR%20FIPS%3D%2728063%27%20OR%20FIPS%3D%2728065%27%20OR%20FIPS%3D%2728067%27%20OR%20FIPS%3D%2728069%27%20OR%20FIPS%3D%2728071%27%20OR%20FIPS%3D%2728073%27%20OR%20FIPS%3D%2728075%27%20OR%20FIPS%3D%2728077%27%20OR%20FIPS%3D%2728079%27%20OR%20FIPS%3D%2728081%27%20OR%20FIPS%3D%2728083%27%20OR%20FIPS%3D%2728085%27%20OR%20FIPS%3D%2728087%27%20OR%20FIPS%3D%2728089%27%20OR%20FIPS%3D%2728091%27%20OR%20FIPS%3D%2728093%27%20OR%20FIPS%3D%2728095%27%20OR%20FIPS%3D%2728097%27%20OR%20FIPS%3D%2728099%27%20OR%20FIPS%3D%2728101%27%20OR%20FIPS%3D%2728103%27%20OR%20FIPS%3D%2728105%27%20OR%20FIPS%3D%2728107%27%20OR%20FIPS%3D%2728109%27%20OR%20FIPS%3D%2728111%27%20OR%20FIPS%3D%2728113%27%20OR%20FIPS%3D%2728115%27%20OR%20FIPS%3D%2728117%27%20OR%20FIPS%3D%2728119%27%20OR%20FIPS%3D%2728121%27%20OR%20FIPS%3D%2728123%27%20OR%20FIPS%3D%2728125%27%20OR%20FIPS%3D%2728127%27%20OR%20FIPS%3D%2728129%27%20OR%20FIPS%3D%2728131%27%20OR%20FIPS%3D%2728133%27%20OR%20FIPS%3D%2728135%27%20OR%20FIPS%3D%2728137%27%20OR%20FIPS%3D%2728139%27%20OR%20FIPS%3D%2728141%27%20OR%20FIPS%3D%2728143%27%20OR%20FIPS%3D%2728145%27%20OR%20FIPS%3D%2728147%27&outFields=NAME%2CFIPS%2CSTATE_ABBR%2CSTATE_NAME&returnGeometry=true&f=geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 50 features and 4 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -91.36562 ymin: 30.19659 xmax: -88.09789 ymax: 34.99593
#> Geodetic CRS:  WGS 84
#> Reading layer `OGRGeoJSON' from data source 
#>   `https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Boundaries_2022/FeatureServer/2/query?where=FIPS%3D%2728149%27%20OR%20FIPS%3D%2728151%27%20OR%20FIPS%3D%2728153%27%20OR%20FIPS%3D%2728155%27%20OR%20FIPS%3D%2728157%27%20OR%20FIPS%3D%2728159%27%20OR%20FIPS%3D%2728161%27%20OR%20FIPS%3D%2728163%27&outFields=NAME%2CFIPS%2CSTATE_ABBR%2CSTATE_NAME&returnGeometry=true&f=geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 8 features and 4 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -91.63695 ymin: 30.9987 xmax: -88.44944 ymax: 34.19255
#> Geodetic CRS:  WGS 84
# }